#
# _*_ coding:UTF-8 _*_
import win32api
import win32con
# import win32gui
import sys
from ctypes import *
import time

point_x = int(sys.argv[1])
point_y = int(sys.argv[2])


class POINT(Structure):
    _fields_ = [("x", c_ulong), ("y", c_ulong)]


def get_mouse_point():
    po = POINT()
    windll.user32.GetCursorPos(byref(po))
    return int(po.x), int(po.y)


def mouse_click(x=None, y=None):
    if x is not None and y is not None:
        mouse_move(x, y)
        time.sleep(0.05)

    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)


# 无需move鼠标,直接click
def mouse_direct_click(x, y):
    if point_x is not None and point_y is not None:
        x = point_x
        y = point_y
    windll.user32.SetCursorPos(x, y)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)
    time.sleep(0.05)


def mouse_dclick(x=None, y=None):
    if x is not None and y is not None:
        mouse_move(x, y)
        time.sleep(0.05)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)


def mouse_move(x, y):
    windll.user32.SetCursorPos(x, y)


if __name__ == "__main__":
    # mouse_click(1024, 470)
    # mouse_direct_click(1821, 8)
    mouse_direct_click(point_x, point_y)
